package org.base23.video.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.base23.video.domain.entity.AiGuidanceMessageEntity;

import java.time.LocalDateTime;
import java.util.List;

/**
 * AI指导对话消息 Mapper
 */
@Mapper
public interface AiGuidanceMessageMapper extends BaseMapper<AiGuidanceMessageEntity> {

    /**
     * 根据会话ID查询消息列表（按序列号排序）
     */
    List<AiGuidanceMessageEntity> selectByConversationIdOrderBySequence(
            @Param("conversationId") String conversationId
    );

    /**
     * 根据会话ID分页查询消息
     */
    IPage<AiGuidanceMessageEntity> selectPageByConversationId(
            Page<AiGuidanceMessageEntity> page,
            @Param("conversationId") String conversationId
    );

    /**
     * 获取会话中的最大序列号
     */
    Integer selectMaxSequenceByConversationId(@Param("conversationId") String conversationId);

    /**
     * 统计会话消息数量
     */
    Integer countByConversationId(@Param("conversationId") String conversationId);

    /**
     * 删除指定时间之前的消息
     */
    int deleteByTimestampBefore(@Param("timestamp") LocalDateTime timestamp);

    /**
     * 根据会话ID删除消息
     */
    int deleteByConversationId(@Param("conversationId") String conversationId);

    /**
     * 批量插入消息
     */
    int insertBatch(@Param("messages") List<AiGuidanceMessageEntity> messages);
} 